#!/bin/sh

set -e

DEB_SUFFIX="$1"
DEB_PACKAGE="darling-${DEB_SUFFIX}"

ARGS_FILE="$(mktemp)"

if [ -d "debian/tmp/${DEB_SUFFIX}" ]; then
	find "debian/tmp/${DEB_SUFFIX}" -type f -exec tools/debian/make-shlibdeps-file "${ARGS_FILE}" {} \;
else
	touch "${ARGS_FILE}"
fi

OUT="$(mktemp)"
DUMMY="$(mktemp)"
clang "${DUMMY}" -x c -shared -o "${OUT}"$(cat ${ARGS_FILE})
dpkg-shlibdeps -T"debian/${DEB_PACKAGE}.substvars" -p"macho" -e"${OUT}" > /dev/null 2>&1

rm -f "${ARGS_FILE}"
rm -f "${OUT}"
rm -f "${DUMMY}"
